/**
 *
 */
package jp.seraph.cui;

import jp.seraph.cui.message.MessageUtil;

/**
 *
 *
 */
public class RenameCommand extends AbstractCommand {
    public RenameCommand(Mode aParent, InternalConsole aConsole){
        super(aParent, aConsole);
    }

    /**
     *
     * @see jp.seraph.cui.AbstractCommand#executeImpl(jp.seraph.cui.SystemNode[], int)
     */
    @Override
    protected void executeImpl(SystemNode[] aArgs, int aArgListIndex) {
        SystemNode tTarget = aArgs[0];
        StringData tNewName = (StringData)aArgs[1];
        Mode tParent = tTarget.getParent();

        if(tParent.getChild(tNewName.getData()) != null)
            throw new IllegalArgumentException(MessageUtil.nodeNameDuplicateError(tNewName.getData()));

        tTarget.setName(tNewName.getData());
    }

    /**
     *
     * @see jp.seraph.cui.Command#getArgumentTypes()
     */
    public SystemNodeType[][] getArgumentTypes() {
        SystemNodeType[][] tResult = new SystemNodeType[1][];
        tResult[0] = new SystemNodeType[]{ SuperType.getInstance(), StringDataType.getInstance() };

        return tResult;
    }

    /**
     *
     * @see jp.seraph.cui.Command#getHelp()
     */
    public String getHelp() {
        return "rename SystemNode \"NewName\" : rename SystemNode.";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getName()
     */
    public String getName() {
        return "rename";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getType()
     */
    public SystemNodeType getType() {
        return RenameCommandType.getInstance();
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#isRoot()
     */
    public boolean isRoot() {
        return false;
    }

}
